package com.tnl.app.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.tnl.app.entity.MyCalendar;
import com.tnl.base.BaseDAO;


@Repository
public class MyCalendarDAO {
	private static final String SQL_GET_ALL = "select * from calendar where hunterid=? order by starttime asc";
	private static final String SQL_GET_TIMEPART="select * from calendar where 1=1 ";
	private static final String SQL_GET_ID="select * from calendar where id=?";
	private static final String SQL_UPDATE_ISBOOKING="update calendar set isbook=? where 1=1";
	public List<MyCalendar> getALL(int hunterid) {
		return BaseDAO.queryForList(MyCalendar.class, SQL_GET_ALL,hunterid);
	}
	
	public List<MyCalendar> getTimePart(int hunterid,String date,int isbook){
		String sql=SQL_GET_TIMEPART;
		sql+=" and hunterid="+hunterid+" and starttime LIKE '"+date+"%' and isbook="+isbook+"";
		return BaseDAO.queryForList(MyCalendar.class, sql);
	}
	
	public MyCalendar getById(String proTimeId){
		return BaseDAO.queryForObject(MyCalendar.class, SQL_GET_ID, proTimeId);
	}
	
	
	public int updateIsBooking(Integer hunterId,String orderTime,int isbook) {
		String sql=SQL_UPDATE_ISBOOKING;
		sql+=" and hunterid="+hunterId+" and starttime LIKE '"+orderTime.substring(0,17).replace("  ", " ")+"%'";
		Long result =BaseDAO.save(sql,isbook);
		if (result != null) {
			return result.intValue();
		}
		return -1;
	}
	
	
}
